import ctypes

# 定义原始输入结构
class MOUSEINPUT(ctypes.Structure):
    _fields_ = [("dx", ctypes.c_long),
                ("dy", ctypes.c_long),
                ("mouseData", ctypes.c_ulong),
                ("dwFlags", ctypes.c_ulong),
                ("time", ctypes.c_ulong),
                ("dwExtraInfo", ctypes.POINTER(ctypes.c_ulong))]

class INPUT(ctypes.Structure):
    _fields_ = [("type", ctypes.c_ulong),
                ("mi", MOUSEINPUT)]

# 定义常量
INPUT_MOUSE = 0
MOUSEEVENTF_MOVE = 0x0001
MOUSEEVENTF_ABSOLUTE = 0x8000
SCREEN_WIDTH = ctypes.windll.user32.GetSystemMetrics(0)
SCREEN_HEIGHT = ctypes.windll.user32.GetSystemMetrics(1)

def move_mouse(dx, dy):
    x = INPUT(type=INPUT_MOUSE,
              mi=MOUSEINPUT(dx=dx, dy=dy, mouseData=0, dwFlags=MOUSEEVENTF_MOVE, time=0, dwExtraInfo=None))
    ctypes.windll.user32.SendInput(1, ctypes.byref(x), ctypes.sizeof(x))

def move_mouse_to(x, y):
    # 将坐标转换为绝对值
    absolute_x = int(65535 * x / SCREEN_WIDTH)
    absolute_y = int(65535 * y / SCREEN_HEIGHT)
    # 移动鼠标到绝对位置
    x = INPUT(type=INPUT_MOUSE,
              mi=MOUSEINPUT(dx=absolute_x, dy=absolute_y, mouseData=0, dwFlags=MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, time=0, dwExtraInfo=None))
    ctypes.windll.user32.SendInput(1, ctypes.byref(x), ctypes.sizeof(x))

def move_mouse_to_stick(x, y):
    absolute_x = int(x/16*9 + 32768)
    absolute_y = int(32767 - y)
    # 移动鼠标到绝对位置
    x = INPUT(type=INPUT_MOUSE,
              mi=MOUSEINPUT(dx=absolute_x, dy=absolute_y, mouseData=0, dwFlags=MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, time=0, dwExtraInfo=None))
    ctypes.windll.user32.SendInput(1, ctypes.byref(x), ctypes.sizeof(x))

if __name__ == "__main__":
    move_mouse_to(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)